// Source File Name:   DataTypeFactory.java

package com.sunwayhorizo.health.hl7.factories;

import java.math.*;
import java.util.*;

import com.sunwayhorizo.health.hl7.common.*;
import com.sunwayhorizo.health.hl7.datatypes.*;
import com.sunwayhorizo.health.hl7.datatypes.common.*;
import com.sunwayhorizo.health.hl7.datatypes.common.gtsparser.*;
import com.sunwayhorizo.health.hl7.vocabulary.*;

public class DataTypeFactory
{

    public static final String RCS_ID = "$Header: DataTypeFactory.java 1.0 2006/02/08 05:05:42 mmoores noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion(
        "$Header: DataTypeFactory.java 1.0 2006/02/08 05:05:42 mmoores noship $", "com.sunwayhorizo.health.hl7.factories");
    // private ServiceLocator mServiceLocator;
    private static final String CLASS_KEY = "CLASS";
    private static final String METHOD_KEY = "METHOD";
    private static final String PARAM_KEY = "PARAM";
    private static final String CAUSE_KEY = "CAUSE";
    private static final String MANDATORY_CODE = "CORE_MANDATORY_ATTRIBUTE";
    private static final String FACTORY_CODE = "CORE_DATATYPE_FACTORY";
    private static final String MANDATORY_MESSAGE = "Mandatory property &PARAM of data type &CLASS must be supplied to the factory method";
    private static final String FACTORY_MESSAGE = "An error occurred while constructing a new instance of &CLASS: &CAUSE";


    public static DataTypeFactory getInstance()
    {
        return new DataTypeFactory();
    }


    // public static DataTypeFactory getInstance(ServiceLocator servicelocator)
    // {
    // if(servicelocator == null)
    // throw new IllegalArgumentException();
    // else
    // return new DataTypeFactory(servicelocator);
    // }

    private DataTypeFactory()
    {
    }


    // private DataTypeFactory(ServiceLocator servicelocator)
    // {
    // mServiceLocator = servicelocator;
    // }

    public BL newBL(boolean flag) throws Hl7Exception
    {
        try
        {
            return BLImpl.valueOf(flag);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("BL", throwable);
        }
    }


    public BL newBL(String s) throws Hl7Exception
    {
        if (s == null)
            return nullBL(NullFlavorImpl.NI);
        try
        {
            return BLImpl.valueOf(s);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("BL", throwable);
        }
    }


    public BL nullBL(CS cs)
    {
        return BLImpl.nullBL(cs);
    }


    public BN newBN(boolean flag) throws Hl7Exception
    {
        try
        {
            return BNImpl.valueOf(flag);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("BN", throwable);
        }
    }


    public BIN nullBIN(CS cs)
    {
        return BINImpl.nullBIN(cs);
    }


    /**
     * new ED
     * 
     * @param s
     * @param cs
     * @param cs1
     * @param cs2
     * @param cs3
     * @param tel
     * @param bin
     * @param cs4
     * @param ed
     * @param cs5
     * @return
     * @throws Hl7Exception
     */
    public ED newED(String s, CS cs, CS cs1, CS cs2, CS cs3, TEL tel, BIN bin, CS cs4, ED ed, CS cs5) throws Hl7Exception
    {
        if (cs == null || cs.isNull().isTrue())
            throw newMandatoryException("ED", "mediaType");
        try
        {
            return EDImpl.valueOf(s, checkNull(cs), checkNull(cs1), checkNull(cs2), checkNull(cs3), checkNull(tel), checkNull

            (bin), checkNull(cs4), checkNull(ed), checkNull(cs5));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("ED", throwable);
        }
    }


    public ED getED(String desc) throws Hl7Exception
    {
        return newED(desc, newCS("ST"), nullCS(NullFlavor.NI), nullCS(NullFlavor.NI), nullCS(NullFlavor.NI), nullTEL(NullFlavor.NI), null,
            nullCS(NullFlavor.NI), null, nullCS(NullFlavor.NI));

    }


    /**
     * new BIN
     * 
     * @param s
     *            byte[]
     * @return BIN
     * @author jinzw
     * @date 2010-11-09
     * @throws Hl7Exception
     */
    public BIN newBIN(byte[] s) throws Hl7Exception
    {
        if (s != null)
        {
            return BINImpl.valueOf(s);
        }
        return null;
    }


    public ED nullED(CS cs)
    {
        return EDImpl.nullED(cs);
    }


    public ST newST(String s) throws Hl7Exception
    {
        if (s == null)
            return null;
        try
        {
            return STImpl.valueOf(s);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("ST", throwable);
        }
    }


    public ST newST(char c) throws Hl7Exception
    {
        try
        {
            return STImpl.valueOf(c);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("ST", throwable);
        }
    }


    public ST newST(String s, CS cs) throws Hl7Exception
    {
        if (s == null)
            return nullST(NullFlavorImpl.NI);
        try
        {
            return STImpl.valueOf(s, checkNull(cs));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("ST", throwable);
        }
    }


    public ST nullST(CS cs)
    {
        return STImpl.nullST(cs);
    }


    public CD newCD(String s) throws Hl7Exception
    {
        // if(s == null)
        // return nullCD(NullFlavorImpl.NI);
        // ETSService etsservice = new ETSServiceImpl();
        // try
        // {
        // return CDImpl.valueOf(etsservice, s);
        // }
        // catch(Throwable throwable)
        // {
        // throw newFactoryException("CD", throwable);
        // }
        if (s == null || s.equals(""))
        {
            return null;
        }
        else
        {
            return CDImpl.valueOf(s);
        }
    }


    /**
     * 修改CD类型改变后带来的错误
     * 
     * jinzw 2010-11-15
     * 
     * @param s
     * @param s1
     * @return
     * @throws Hl7Exception
     */
    public CD newCD(String s, String s1) throws Hl7Exception
    {
        if (s == null || s == "")
            throw newMandatoryException("CD", "code");
        if (s1 == null || s1 == "")
            throw newMandatoryException("CD", "codeSystem");
        OID oid;
        try
        {
            oid = OIDImpl.valueOf(s1);
        }
        catch (Exception exception)
        {
            throw ANYImpl.newParseException("CD", s1, exception);
        }
        catch (TokenMgrError tokenmgrerror)
        {
            throw ANYImpl.newParseException("CD", s1, tokenmgrerror);
        }
        try
        {
            return null;
        }
        catch (Exception exception1)
        {
            throw newFactoryException("CD", exception1);
        }
    }


    /**
     * 增加一个创建CD的方法，默认传入一个英文名称 jinzw 2010-11-15
     * 
     * @param st
     * @param uid
     * @param st1
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeSystemEnName
     * @param st2
     * @param ed
     * @return
     * @throws Hl7Exception
     */
    public CD newCD(ST st, UID uid, ST st1, ST st2, ED ed) throws Hl7Exception
    {
        if (st == null || st.isNull().isTrue())
            throw newMandatoryException("CD", "code");
        OID oid;
        if (uid == null || uid.isNull().isTrue())
            oid = nullOID(NullFlavorImpl.NI);
        else
            try
            {
                oid = OIDImpl.valueOf(uid.literal().stringValue());
            }
            catch (Exception exception)
            {
                throw ANYImpl.newParseException("CD", uid.stringValue(), exception);
            }
            catch (TokenMgrError tokenmgrerror)
            {
                throw ANYImpl.newParseException("CD", uid.stringValue(), tokenmgrerror);
            }
        try
        {
            return null;
        }
        catch (Exception exception1)
        {
            throw newFactoryException("CD", exception1);
        }
    }


    /**
     * 修改方法，增加参数ST st3,ST st4
     * 
     * jinzw 2010-11-15
     * 
     * @param st
     * @param uid
     * @param st1
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeSystemEnName
     * @param st2
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeSystemChName
     * @param st3
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeName
     * @param st4
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeSystemVersion
     * @param ed
     * @return
     * @throws Hl7Exception
     */
    public CD newCD(ST st, UID uid, ST st1, ST st2, ST st3, ST st4, ED ed) throws Hl7Exception
    {
        if (st == null || st.isNull().isTrue())
            throw newMandatoryException("CD", "code");
        OID oid;
        if (uid == null || uid.isNull().isTrue())
            oid = nullOID(NullFlavorImpl.NI);
        else
            try
            {
                oid = OIDImpl.valueOf(uid.literal().stringValue());
            }
            catch (Exception exception)
            {
                throw ANYImpl.newParseException("CD", uid.stringValue(), exception);
            }
            catch (TokenMgrError tokenmgrerror)
            {
                throw ANYImpl.newParseException("CD", uid.stringValue(), tokenmgrerror);
            }
        try
        {
            return null;
        }
        catch (Exception exception1)
        {
            throw newFactoryException("CD", exception1);
        }
    }


    public CD nullCD(CS cs)
    {
        return CDImpl.nullCD(cs);
    }


    public CS newCS(String s) throws Hl7Exception
    {
        if (s == null || s.equals(""))
            return null;
        try
        {
            return CSImpl.valueOf(s);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("CS", throwable);
        }
    }


    public CS nullCS(CS cs)
    {
        return CSImpl.nullCS(cs);
    }


    /**
     * 修改CD数据类型改变后带来的错误
     * 
     * jinzw 2010-11-15
     * 
     * @param s
     * @param s1
     * @return
     * @throws Hl7Exception
     */
    public CV newCV(String s, String s1) throws Hl7Exception
    {
        if (s == null || s == "")
            throw newMandatoryException("CV", "code");
        if (s1 == null || s1 == "")
            throw newMandatoryException("CV", "codeSystem");
        OID oid;
        try
        {
            oid = OIDImpl.valueOf(s1);
        }
        catch (Exception exception)
        {
            throw ANYImpl.newParseException("CV", s1, exception);
        }
        catch (TokenMgrError tokenmgrerror)
        {
            throw ANYImpl.newParseException("CV", s1, tokenmgrerror);
        }
        try
        {
            ST st = nullST(NullFlavorImpl.NI);
            //2012 zhushi
//            return CVImpl.valueOf(newST(s), oid, st, st, st, st, st, nullED(NullFlavorImpl.NI));
            return null;
        }
        catch (Exception exception1)
        {
            throw newFactoryException("CV", exception1);
        }
    }


    /**
     * 修改方法，增加参数ST st3,ST st4
     * 
     * jinzw 2010-11-15
     * 
     * @param st
     * @param uid
     * @param st1
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeSystemEnName
     * @param st2
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeSystemChName
     * @param st3
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeName
     * @param st4
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeSystemVersion
     * @param ed
     * @return
     * @throws Hl7Exception
     */
    public CV newCV(ST st, UID uid, ST st1, ST st2, ST st3, ST st4, ED ed) throws Hl7Exception
    {
        if (st == null || st.isNull().isTrue())
            throw newMandatoryException("CV", "code");
        OID oid;
        if (uid == null || uid.isNull().isTrue())
            oid = nullOID(NullFlavorImpl.NI);
        else
            try
            {
                oid = OIDImpl.valueOf(uid.literal().stringValue());
            }
            catch (Exception exception)
            {
                throw ANYImpl.newParseException("CV", uid.stringValue(), exception);
            }
            catch (TokenMgrError tokenmgrerror)
            {
                throw ANYImpl.newParseException("CV", uid.stringValue(), tokenmgrerror);
            }
        try
        {
            return null;
        }
        catch (Exception exception1)
        {
            throw newFactoryException("CV", exception1);
        }
    }


    public CV nullCV(CS cs)
    {
        return CVImpl.nullCV(cs);
    }


    /**
     * 新增通过一个code构造CE
     * 
     * jinzw 2010-11-19
     * 
     * @param code
     * @return
     */
    public CE newCE(String code)
    {
        return CEImpl.valueOf(code);
    }


    /**
     * 增加一个构造CE的方法，传递6个参数
     * 
     * jinzw 2010-11-19
     * 
     * @param code
     * @param codeSystem
     * @param codeSystemEnName
     * @param codeSystemChName
     * @param codeName
     * @param codeSystemVersion
     * @return
     */
    public CE newCE(String code, String codeSystem, String codeSystemEnName, String codeSystemChName, String codeName, String

    codeSystemVersion)
    {
        return CEImpl.valueOf(code, codeSystem, codeSystemEnName, codeSystemChName, codeName, codeSystemVersion);
    }


    /**
     * 修改方法，默认传入一个英文名称
     * 
     * jinzw 2010-11-15
     * 
     * @param st
     * @param uid
     * @param st1
     * @param st2
     * @param ed
     * @return
     * @throws Hl7Exception
     */
    public CE newCE(ST st, UID uid, ST st1, ST st2, ED ed) throws Hl7Exception
    {
        if (st == null || st.isNull().isTrue())
            throw newMandatoryException("CE", "code");
        OID oid;
        if (uid == null || uid.isNull().isTrue())
            oid = nullOID(NullFlavorImpl.NI);
        else
            try
            {
                oid = OIDImpl.valueOf(uid.literal().stringValue());
            }
            catch (Exception exception)
            {
                throw ANYImpl.newParseException("CE", uid.stringValue(), exception);
            }
            catch (TokenMgrError tokenmgrerror)
            {
                throw ANYImpl.newParseException("CE", uid.stringValue(), tokenmgrerror);
            }
        try
        {
            return null;
        }
        catch (Exception exception1)
        {
            throw newFactoryException("CE", exception1);
        }
    }


    /**
     * 修改方法，增加参数ST st3,ST st4
     * 
     * jinzw 2010-11-15
     * 
     * @param st
     * @param uid
     * @param st1
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeSystemEnName
     * @param st2
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeSystemChName
     * @param st3
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeName
     * @param st4
     *            对应com.sunwayhorizo.health.hl7.datatypes.common.
     *            CDImpl中的mCodeSystemVersion
     * @param ed
     * @return
     * @throws Hl7Exception
     */
    public CE newCE(ST st, UID uid, ST st1, ST st2, ST st3, ST st4, ED ed) throws Hl7Exception
    {
        if (st == null || st.isNull().isTrue())
            throw newMandatoryException("CE", "code");
        OID oid;
        if (uid == null || uid.isNull().isTrue())
            oid = nullOID(NullFlavorImpl.NI);
        else
            try
            {
                oid = OIDImpl.valueOf(uid.literal().stringValue());
            }
            catch (Exception exception)
            {
                throw ANYImpl.newParseException("CE", uid.stringValue(), exception);
            }
            catch (TokenMgrError tokenmgrerror)
            {
                throw ANYImpl.newParseException("CE", uid.stringValue(), tokenmgrerror);
            }
        try
        {
            return null;
        }
        catch (Exception exception1)
        {
            throw newFactoryException("CE", exception1);
        }
    }


    public CE nullCE(CS cs)
    {
        return CEImpl.nullCE(cs);
    }


    public SC newSC(String s, CE ce) throws Hl7Exception
    {
        if (s == null)
            throw newMandatoryException("SC", "value");
        try
        {
            return SCImpl.valueOf(s, checkNull(ce));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SC", throwable);
        }
    }


    public SC newSC(String s) throws Hl7Exception
    {
        if (s == null)
            return nullSC(NullFlavorImpl.NI);
        try
        {
            return SCImpl.valueOf(s);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SC", throwable);
        }
    }


    public SC nullSC(CS cs)
    {
        return SCImpl.nullSC(cs);
    }


    public UID newUID(String s) throws Hl7Exception
    {
        if (s == null)
            return nullUID(NullFlavorImpl.NI);
        try
        {
            return UIDImpl.valueOf(s);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("UID", throwable);
        }
    }


    public UID nullUID(CS cs)
    {
        return UIDImpl.nullUID(cs);
    }


    public II newII(String s, String s1, String iiState) throws Hl7Exception
    {
        if (s == null || s == "")
            throw newMandatoryException("II", "root");
        OID oid;
        try
        {
            oid = OIDImpl.valueOf(s);
        }
        catch (Exception exception)
        {
            throw ANYImpl.newParseException("II", s, exception);
        }
        catch (TokenMgrError tokenmgrerror)
        {
            throw ANYImpl.newParseException("II", s, tokenmgrerror);
        }
        ST st = newST(s1);
        ST state = newST(iiState);
        try
        {
            return IIImpl.valueOf(oid, st, state);
        }
        catch (Exception exception1)
        {
            throw newFactoryException("II", exception1);
        }
    }


    public II newII(String root, String extension, String state, String identifierName, String clinicNo) throws Hl7Exception
    {
        if (root == null || root == "")
            throw newMandatoryException("II", "root");
        OID oid;
        try
        {
            oid = OIDImpl.valueOf(root);
        }
        catch (Exception exception)
        {
            throw ANYImpl.newParseException("II", root, exception);
        }
        catch (TokenMgrError tokenmgrerror)
        {
            throw ANYImpl.newParseException("II", root, tokenmgrerror);
        }
        ST _extension = newST(extension);
        ST _state = newST(state);
        ST _identifierName = newST(identifierName);
        ST _clinicNo = newST(clinicNo);
        try
        {
            return IIImpl.valueOf(oid, _extension, _identifierName, _state, _clinicNo);
        }
        catch (Exception exception1)
        {
            throw newFactoryException("II", exception1);
        }
    }


    public II newII(String root, String extension, String state, String identifierName) throws Hl7Exception
    {
        if (root == null || root == "")
            throw newMandatoryException("II", "root");
        OID oid;
        try
        {
            oid = OIDImpl.valueOf(root);
        }
        catch (Exception exception)
        {
            throw ANYImpl.newParseException("II", root, exception);
        }
        catch (TokenMgrError tokenmgrerror)
        {
            throw ANYImpl.newParseException("II", root, tokenmgrerror);
        }
        ST _extension = newST(extension);
        ST _state = newST(state);
        ST _identifierName = newST(identifierName);
        try
        {
            return IIImpl.valueOf(oid, _extension, _identifierName, _state);
        }
        catch (Exception exception1)
        {
            throw newFactoryException("II", exception1);
        }
    }


    public II newII(UID uid, ST st, ST bl) throws Hl7Exception
    {
        if (uid == null || uid.isNull().isTrue())
            throw newMandatoryException("II", "root");
        OID oid;
        try
        {
            oid = OIDImpl.valueOf(uid.toString());
        }
        catch (Exception exception)
        {
            throw ANYImpl.newParseException("II", uid.toString(), exception);
        }
        catch (TokenMgrError tokenmgrerror)
        {
            throw ANYImpl.newParseException("II", uid.toString(), tokenmgrerror);
        }
        try
        {
            return IIImpl.valueOf(oid, checkNull(st), checkNull(bl));
        }
        catch (Exception exception1)
        {
            throw newFactoryException("II", exception1);
        }
    }


    /**
     * 根据参数创建一个II
     * 
     * @param uid
     * @param extension
     *            ii唯一性编号
     * @param identifierName
     *            唯一标示符
     * @param iiType
     *            ii类型（如身份证，军官证，医保证等）
     * @param iiSouce
     *            II来源（如发证机关）
     * @param iiState
     *            ii状态（如启用，未启用等）
     * @return II
     * @throws Hl7Exception
     */
    public II newII(UID uid, ST extension, ST identifierName, CE iiType, ST iiSouce, ST iiState) throws Hl7Exception
    {
        try
        {
            return IIImpl.valueOf(uid, checkNull(extension), checkNull(identifierName), checkNull(iiType), checkNull(iiSouce), checkNull(iiState));
        }
        catch (Exception exception1)
        {
            throw newFactoryException("II", exception1);
        }
    }


    public II nullII(CS cs)
    {
        return IIImpl.nullII(cs);
    }


    public URL newURL(CS cs, ST st) throws Hl7Exception
    {
        try
        {
            return URLImpl.valueOf(checkNull(cs), checkNull(st));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("URL", throwable);
        }
    }


    public URL newURL(String s, String s1) throws Hl7Exception
    {
        if (s == null || s1 == null)
            return nullURL(NullFlavorImpl.NI);
        try
        {
            return URLImpl.valueOf(s, s1);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("URL", throwable);
        }
    }


    public URL nullURL(CS cs)
    {
        return URLImpl.nullURL(cs);
    }


    public TEL newTEL(CS cs, ST st, GTS gts, SET_CS set_cs) throws Hl7Exception
    {
        try
        {
            return TELImpl.valueOf(checkNull(cs), checkNull(st), checkNull(gts), checkNull(set_cs));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("TEL", throwable);
        }
    }


    public TEL newTEL(String s, String s1, GTS gts, SET_CS set_cs) throws Hl7Exception
    {
        if (s == null || s1 == null)
            return nullTEL(NullFlavorImpl.NI);
        try
        {
            return TELImpl.valueOf(s, s1, checkNull(gts), checkNull(set_cs));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("TEL", throwable);
        }
    }


    public TEL nullTEL(CS cs)
    {
        return TELImpl.nullTEL(cs);
    }


    public ADXP newADXP(String s, CS cs) throws Hl7Exception
    {
        if (s == null)
            return nullADXP(NullFlavorImpl.NI);
        try
        {
            return ADXPImpl.valueOf(s, checkNull(cs));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("ADXP", throwable);
        }
    }


    public ADXP nullADXP(CS cs)
    {
        return ADXPImpl.nullADXP(cs);
    }


    public AD nullAD(CS cs)
    {
        return ADImpl.nullAD(cs);
    }


    public AD newAD(ADXP aadxp[], SET_CS set_cs, GTS gts, ST st) throws Hl7Exception
    {
        try
        {
            return ADImpl.valueOf(aadxp, checkNull(set_cs), checkNull(gts), st);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("AD", throwable);
        }
    }


    public ENXP newENXP(String s, CS cs, SET_CS set_cs) throws Hl7Exception
    {
        if (s == null)
            return nullENXP(NullFlavorImpl.NI);
        try
        {
            return ENXPImpl.valueOf(s, checkNull(cs), checkNull(set_cs));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("ENXP", throwable);
        }
    }


    public ENXP nullENXP(CS cs)
    {
        return ENXPImpl.nullENXP(cs);
    }


    public EN nullEN(CS cs)
    {
        return ENImpl.nullEN(cs);
    }


    // ����ENʱ������formatted����st
    public EN newEN(ENXP aenxp[], SET_CS set_cs, IVL_TS ivl_ts, ST st) throws Hl7Exception
    {
        try
        {
            return ENImpl.valueOf(aenxp, checkNull(set_cs), checkNull(ivl_ts), st);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("EN", throwable);
        }
    }
    
    public EN newEN(ENXP aenxp[], SET_CS set_cs, IVL_TS ivl_ts, ST st,ST flag) throws Hl7Exception
    {
        try
        {
            return ENImpl.valueOf(aenxp, checkNull(set_cs), checkNull(ivl_ts), st,flag);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("EN", throwable);
        }
    }



    public EN newEN(ST name, CS use)
    {
        return ENImpl.valueOf(name, use);
    }


    public ON nullON(CS cs)
    {
        return ONImpl.nullON(cs);
    }


    public ON newON(ENXP aenxp[], SET_CS set_cs, IVL_TS ivl_ts) throws Hl7Exception
    {
        try
        {
            return ONImpl.valueOf(aenxp, checkNull(set_cs), checkNull(ivl_ts));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("ON", throwable);
        }
    }


    public PN nullPN(CS cs)
    {
        return PNImpl.nullPN(cs);
    }


    public PN newPN(ENXP aenxp[], SET_CS set_cs, IVL_TS ivl_ts) throws Hl7Exception
    {
        try
        {
            return PNImpl.valueOf(aenxp, checkNull(set_cs), checkNull(ivl_ts));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("PN", throwable);
        }
    }


    public TN newTN(String s) throws Hl7Exception
    {
        if (s == null)
            return nullTN(NullFlavorImpl.NI);
        try
        {
            return TNImpl.valueOf(s);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("TN", throwable);
        }
    }


    public TN nullTN(CS cs)
    {
        return TNImpl.nullTN(cs);
    }


    public INT newINT(String s) throws Hl7Exception
    {
        return newINT(Long.parseLong(s));
    }


    public INT newINT(long l) throws Hl7Exception
    {
        try
        {
            return INTImpl.valueOf(l);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("INT", throwable);
        }
    }


    public INT nullINT(CS cs)
    {
        return INTImpl.nullINT(cs);
    }


    public REAL newREAL(String s) throws Hl7Exception
    {
        if (s == null)
            return null;
        try
        {
            return REALImpl.valueOf(s);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("REAL", throwable);
        }
    }


    public REAL newREAL(BigDecimal bigdecimal) throws Hl7Exception
    {
        if (bigdecimal == null)
            return nullREAL(NullFlavorImpl.NI);
        try
        {
            return REALBigDecimalImpl.valueOf(bigdecimal);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("REAL", throwable);
        }
    }


    public REAL nullREAL(CS cs)
    {
        return REALImpl.nullREAL(cs);
    }


    public RTO_PQ newRTO_PQ() throws Hl7Exception
    {
        try
        {
            return RTO_PQImpl.valueOf();
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("RTO<PQ>", throwable);
        }
    }


    public RTO_PQ newRTO_PQ(PQ pq, PQ pq1) throws Hl7Exception
    {
        try
        {
            return RTO_PQImpl.valueOf(checkNull(pq), checkNull(pq1));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("RTO<PQ>", throwable);
        }
    }


    public RTO_PQ nullRTO_PQ(CS cs)
    {
        return RTO_PQImpl.nullRTO_PQ(cs);
    }


    public RTO_INT newRTO_INT() throws Hl7Exception
    {
        try
        {
            return RTO_INTImpl.valueOf();
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("RTO<INT>", throwable);
        }
    }


    public RTO_INT newRTO_INT(INT int1, INT int2) throws Hl7Exception
    {
        try
        {
            return RTO_INTImpl.valueOf(checkNull(int1), checkNull(int2));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("RTO<INT>", throwable);
        }
    }


    public RTO_INT newRTO_INT(long l, long l1) throws Hl7Exception
    {
        INT int1 = INTImpl.valueOf(l);
        INT int2 = INTImpl.valueOf(l1);
        return newRTO_INT(int1, int2);
    }


    public RTO_INT nullRTO_INT(CS cs)
    {
        return RTO_INTImpl.nullRTO_INT(cs);
    }


    public PQ newPQ(REAL real, CS cs) throws Hl7Exception
    {
        if (real == null || real.isNull().isTrue())
           return null;
        if (cs == null || cs.isNull().isTrue())
           return null;
        try
        {
            return PQImpl.valueOf(real, cs);
        }
        catch (RuntimeException runtimeexception)
        {
            throw newFactoryException("PQ", runtimeexception);
        }
    }


    public PQ newPQ(String s, String s1) throws Hl7Exception
    {
        if (s == null)
            throw newMandatoryException("PQ", "value");
        if (s1 == null)
            throw newMandatoryException("PQ", "unit");
        try
        {
            return PQImpl.valueOf(s, s1);
        }
        catch (RuntimeException runtimeexception)
        {
            throw newFactoryException("PQ", runtimeexception);
        }
    }


    public PQ nullPQ(CS cs)
    {
        return PQImpl.nullPQ(cs);
    }


    public MO newMO(REAL real, CS cs) throws Hl7Exception
    {
        try
        {
            return MOImpl.valueOf(checkNull(real), checkNull(cs));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("MO", throwable);
        }
    }


    public MO newMO(BigDecimal bigdecimal, String s) throws Hl7Exception
    {
        REAL real = newREAL(bigdecimal);
        CS cs = newCS(s);
        return newMO(real, cs);
    }


    public MO nullMO(CS cs)
    {
        return MOImpl.nullMO(cs);
    }


    public SET_II nullSET_II(CS cs)
    {
        return SET_IIImpl.nullSET_II(cs);
    }


    public SET_II newSET_II(II aii[]) throws Hl7Exception
    {
        if (aii == null)
            return nullSET_II(NullFlavorImpl.NI);
        try
        {
            return SET_IIImpl.valueOf(aii);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<II>", throwable);
        }
    }


    public SET_II newSET_II(II ii) throws Hl7Exception
    {
        if (ii == null || ii.isNull().isTrue())
            return nullSET_II(NullFlavorImpl.NI);
        try
        {
            return SET_IIImpl.valueOf(ii);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<II>", throwable);
        }
    }


    public SET_II newSET_II(String s, String s1, String iiState) throws Hl7Exception
    {
        return newSET_II(newII(s, s1, iiState));
    }


    public SET_II newSET_II(String s, String s1, String iiState, String identifierName) throws Hl7Exception
    {
        return newSET_II(newII(s, s1, iiState, identifierName));
    }


    public SET_CD nullSET_CD(CS cs)
    {
        return SET_CDImpl.nullSET_CD(cs);
    }


    public SET_CD newSET_CD(CD acd[]) throws Hl7Exception
    {
        if (acd == null)
            return nullSET_CD(NullFlavorImpl.NI);
        try
        {
            return SET_CDImpl.valueOf(acd);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<CD>", throwable);
        }
    }


    public SET_CD newSET_CD(CD cd) throws Hl7Exception
    {
        if (cd == null || cd.isNull().isTrue())
            return nullSET_CD(NullFlavorImpl.NI);
        try
        {
            return SET_CDImpl.valueOf(cd);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<CD>", throwable);
        }
    }


    public SET_CD newSET_CD(String as[]) throws Hl7Exception
    {
        if (as == null || as.length == 0)
        {
            return nullSET_CD(NullFlavorImpl.NI);
        }
        else
        {
            return null;
//            return SET_CDImpl.newSET_CD(etsservice, as);
        }
    }


    public SET_CS newSET_CS(CS acs[]) throws Hl7Exception
    {
        if (acs == null || acs.length == 0)
            return nullSET_CS(NullFlavorImpl.NI);
        try
        {
            return SET_CSImpl.valueOf(acs);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<CS>", throwable);
        }
    }


    public SET_CS newSET_CS(CS cs) throws Hl7Exception
    {
        if (cs == null || cs.isNull().isTrue())
            return nullSET_CS(NullFlavorImpl.NI);
        try
        {
            return SET_CSImpl.valueOf(cs);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<CS>", throwable);
        }
    }
    
    /**
     * waitbin
     * @param cs
     * @param flag
     * @return
     * @throws Hl7Exception
     */
    public SET_CS newSET_CS(CS cs,ST flag) throws Hl7Exception
    {
        if (cs == null || cs.isNull().isTrue())
            return null;
        try
        {
            return SET_CSImpl.valueOf(cs,flag);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<CS>", throwable);
        }
    }


    public SET_CS nullSET_CS(CS cs)
    {
        return SET_CSImpl.nullSET_CS(cs);
    }


    public SET_CE newSET_CE(CE ace[]) throws Hl7Exception
    {
        if (ace == null || ace.length == 0)
            return null;
        try
        {
            return SET_CEImpl.valueOf(ace);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<CE>", throwable);
        }
    }


    public SET_CE newSET_CE(CE ce) throws Hl7Exception
    {
        if (ce == null || ce.isNull().isTrue())
            return null;
        try
        {
            return SET_CEImpl.valueOf(ce);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<CE>", throwable);
        }
    }


    public SET_CE newSET_CE(String as[]) throws  Hl7Exception
    {
        if (as == null || as.length == 0)
        {
            return nullSET_CE(NullFlavorImpl.NI);
        }
        else
        {
              return null;
//            return SET_CEImpl.newSET_CE(etsservice, as);
        }
    }


    public SET_CE nullSET_CE(CS cs)
    {
        return SET_CEImpl.nullSET_CE(cs);
    }


    public SET_INT nullSET_INT(CS cs)
    {
        return SET_INTImpl.nullSET_INT(cs);
    }


    public SET_INT newSET_INT(INT aint[]) throws Hl7Exception
    {
        if (aint == null || aint.length == 0)
            return nullSET_INT(NullFlavorImpl.NI);
        try
        {
            return SET_INTImpl.valueOf(aint);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<INT>", throwable);
        }
    }


    public SET_INT newSET_INT(long al[]) throws Hl7Exception
    {
        if (al == null || al.length == 0)
            return nullSET_INT(NullFlavorImpl.NI);
        try
        {
            return SET_INTImpl.valueOf(al);
        }
        catch (Exception exception)
        {
            throw newFactoryException("SET<INT>", exception);
        }
    }


    public SET_INT newSET_INT(long l) throws Hl7Exception
    {
        INT int1 = INTImpl.valueOf(l);
        return newSET_INT(int1);
    }


    public SET_INT newSET_INT(INT int1) throws Hl7Exception
    {
        if (int1 == null || int1.isNull().isTrue())
            return nullSET_INT(NullFlavorImpl.NI);
        try
        {
            return SET_INTImpl.valueOf(int1);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<INT>", throwable);
        }
    }


    public SET_PQ nullSET_PQ(CS cs)
    {
        return SET_PQImpl.nullSET_PQ(cs);
    }


    public SET_PQ newSET_PQ(PQ apq[]) throws Hl7Exception
    {
        if (apq == null || apq.length == 0)
            return nullSET_PQ(NullFlavorImpl.NI);
        try
        {
            return SET_PQImpl.valueOf(apq);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<PQ>", throwable);
        }
    }


    public SET_PQ newSET_PQ(PQ pq) throws Hl7Exception
    {
        if (pq == null || pq.isNull().isTrue())
            return null;
        try
        {
            return SET_PQImpl.valueOf(pq);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<PQ>", throwable);
        }
    }


    public SET_RTO_PQ nullSET_RTO_PQ(CS cs)
    {
        return SET_RTO_PQImpl.nullSET_RTO_PQ(cs);
    }


    public SET_RTO_PQ newSET_RTO_PQ(RTO_PQ arto_pq[]) throws Hl7Exception
    {
        if (arto_pq == null || arto_pq.length == 0)
            return nullSET_RTO_PQ(NullFlavorImpl.NI);
        try
        {
            return SET_RTO_PQImpl.valueOf(arto_pq);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<RTO_PQ>", throwable);
        }
    }


    public SET_RTO_PQ newSET_RTO_PQ(RTO_PQ rto_pq) throws Hl7Exception
    {
        if (rto_pq == null || rto_pq.isNull().isTrue())
            return nullSET_RTO_PQ(NullFlavorImpl.NI);
        try
        {
            return SET_RTO_PQImpl.valueOf(rto_pq);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("SET<RTO_PQ>", throwable);
        }
    }


    public LIST_INT nullLIST_INT(CS cs)
    {
        return LIST_INTAdapterImpl.nullLIST_INT(cs);
    }


    public LIST_INT newLIST_INT(INT aint[]) throws Hl7Exception
    {
        if (aint == null || aint.length == 0)
            return nullLIST_INT(NullFlavorImpl.NI);
        try
        {
            return LIST_INTAdapterImpl.valueOf(aint);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("LIST<INT>", throwable);
        }
    }


    public LIST_INT newLIST_INT(INT int1) throws Hl7Exception
    {
        if (int1 == null || int1.isNull().isTrue())
            return nullLIST_INT(NullFlavorImpl.NI);
        try
        {
            return LIST_INTAdapterImpl.valueOf(int1);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("LIST<INT>", throwable);
        }
    }


    public LIST_ENXP nullLIST_ENXP(CS cs)
    {
        return LIST_ENXPAdapterImpl.nullLIST_ENXP(cs);
    }


    public LIST_ENXP newLIST_ENXP(ENXP aenxp[]) throws Hl7Exception
    {
        if (aenxp == null || aenxp.length == 0)
            return nullLIST_ENXP(NullFlavorImpl.NI);
        try
        {
            return LIST_ENXPAdapterImpl.valueOf(aenxp);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("LIST<ENXP>", throwable);
        }
    }


    public LIST_ENXP newLIST_ENXP(ENXP enxp) throws Hl7Exception
    {
        if (enxp == null || enxp.isNull().isTrue())
            return nullLIST_ENXP(NullFlavorImpl.NI);
        try
        {
            return LIST_ENXPAdapterImpl.valueOf(enxp);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("LIST<ENXP>", throwable);
        }
    }


    public LIST_ADXP nullLIST_ADXP(CS cs)
    {
        return LIST_ADXPAdapterImpl.nullLIST_ADXP(cs);
    }


    public LIST_ADXP newLIST_ADXP(ADXP aadxp[]) throws Hl7Exception
    {
        if (aadxp == null || aadxp.length == 0)
            return nullLIST_ADXP(NullFlavorImpl.NI);
        try
        {
            return LIST_ADXPAdapterImpl.valueOf(aadxp);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("LIST<ADXP>", throwable);
        }
    }


    public LIST_ADXP newLIST_ADXP(ADXP adxp) throws Hl7Exception
    {
        if (adxp == null || adxp.isNull().isTrue())
            return nullLIST_ADXP(NullFlavorImpl.NI);
        try
        {
            return LIST_ADXPAdapterImpl.valueOf(adxp);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("LIST<ADXP>", throwable);
        }
    }


    public BAG_TEL nullBAG_TEL(CS cs)
    {
        return BAG_TELImpl.nullBAG_TEL(cs);
    }


    public BAG_TEL newBAG_TEL(TEL atel[]) throws Hl7Exception
    {
        if (atel == null || atel.length == 0)
            return nullBAG_TEL(NullFlavorImpl.NI);
        try
        {
            return BAG_TELImpl.valueOf(atel);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("BAG<TEL>", throwable);
        }
    }


    public BAG_TEL newBAG_TEL(TEL tel) throws Hl7Exception
    {
        if (tel == null || tel.isNull().isTrue())
            return nullBAG_TEL(NullFlavorImpl.NI);
        try
        {
            return BAG_TELImpl.valueOf(tel);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("BAG<TEL>", throwable);
        }
    }


    public BAG_EN nullBAG_EN(CS cs)
    {
        return BAG_ENImpl.nullBAG_EN(cs);
    }


    public BAG_EN newBAG_EN(EN aen[]) throws Hl7Exception
    {
        if (aen == null || aen.length == 0)
            return nullBAG_EN(NullFlavorImpl.NI);
        try
        {
            return BAG_ENImpl.valueOf(aen);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("BAG<EN>", throwable);
        }
    }


    public BAG_EN newBAG_EN(EN en) throws Hl7Exception
    {
        if (en == null || en.isNull().isTrue())
            return nullBAG_EN(NullFlavorImpl.NI);
        try
        {
            return BAG_ENImpl.valueOf(en);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("BAG<EN>", throwable);
        }
    }


    public BAG_AD nullBAG_AD(CS cs)
    {
        return BAG_ADImpl.nullBAG_AD(cs);
    }


    public BAG_AD newBAG_AD(AD aad[]) throws Hl7Exception
    {
        if (aad == null || aad.length == 0)
            return nullBAG_AD(NullFlavorImpl.NI);
        try
        {
            return BAG_ADImpl.valueOf(aad);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("BAG<AD>", throwable);
        }
    }


    public BAG_AD newBAG_AD(AD ad) throws Hl7Exception
    {
        if (ad == null || ad.isNull().isTrue())
            return nullBAG_AD(NullFlavorImpl.NI);
        try
        {
            return BAG_ADImpl.valueOf(ad);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("BAG<AD>", throwable);
        }
    }


    public IVL_INT newIVL_INT(INT int1, BL bl, INT int2, BL bl1) throws Hl7Exception
    {
        if ((int1 == null || int1.isNull().isTrue()) && (int2 == null || int2.isNull().isTrue()))
            throw newMandatoryException("IVL<INT>", "boundary");
        try
        {
            return IVL_INTImpl.valueOf(checkNull(int1), checkNull(bl), checkNull(int2), checkNull(bl1));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<INT>", throwable);
        }
    }


    public IVL_INT newIVL_INT(INT int1) throws Hl7Exception
    {
        if (int1 == null || int1.isNull().isTrue())
            return nullIVL_INT(NullFlavorImpl.NI);
        try
        {
            return IVL_INTImpl.valueOf(int1, BLImpl.TRUE, int1, BLImpl.TRUE);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<INT>", throwable);
        }
    }


    public IVL_INT newIVL_INT(long l) throws Hl7Exception
    {
        INT int1 = newINT(l);
        return newIVL_INT(int1);
    }


    public IVL_INT newIVL_INT(long l, boolean flag, long l1, boolean flag1) throws Hl7Exception
    {
        INT int1 = newINT(l);
        BL bl = newBL(flag);
        INT int2 = newINT(l1);
        BL bl1 = newBL(flag1);
        return newIVL_INT(int1, bl, int2, bl1);
    }


    public IVL_INT nullIVL_INT(CS cs)
    {
        return IVL_INTImpl.nullIVL_INT(cs);
    }


    public IVL_TS newIVL_TS(String s) throws Hl7Exception
    {
        if (s == null)
            return nullIVL_TS(NullFlavorImpl.NI);
        else
            return IVL_TSImpl.valueOf(s);
    }


    public IVL_TS newIVL_TS(TS startDate, TS endDate) throws Hl7Exception
    {
        return IVL_TSImpl.valueOf(startDate,  endDate);

    }


    public IVL_TS newIVL_TS(TS ts) throws Hl7Exception
    {
        if (ts == null || ts.isNull().isTrue())
            return nullIVL_TS(NullFlavorImpl.NI);
        try
        {
            return IVL_TSImpl.valueOf(ts);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<TS>", throwable);
        }
    }


    public IVL_TS newIVL_TS(TS ts, BL bl, TS ts1, BL bl1, PQ pq, TS ts2) throws Hl7Exception
    {
        if ((ts == null || ts.isNull().isTrue()) && (ts1 == null || ts1.isNull().isTrue()))
        {
            if (pq == null || pq.isNull().isTrue())
                throw newMandatoryException("IVL<TS>", "boundary");
            WidthIVL_TSImpl widthivl_tsimpl = WidthIVL_TSImpl.valueOf(checkNull(bl), pq, checkNull(bl1));
            if (ts2 == null || ts2.isNull().isTrue())
                return widthivl_tsimpl;
            else
                return WidthIVL_TSImpl.valueOf(ts2, widthivl_tsimpl);
        }
        if ((ts == null || ts.isNull().isTrue() || ts1 == null || ts1.isNull().isTrue()) && (pq == null || pq.isNull().isTrue

        ()) && ts2 != null && ts2.isNull().isFalse())
            throw newMandatoryException("IVL<TS>", "width");
        else
            return IVL_TSImpl.valueOf(checkNull(ts), checkNull(bl), checkNull(ts1), checkNull(bl1), checkNull(pq));
    }


    public IVL_TS newIVL_TS(TS ts, BL bl, TS ts1, BL bl1) throws Hl7Exception
    {
        if ((ts == null || ts.isNull().isTrue()) && (ts1 == null || ts1.isNull().isTrue()))
            return null;
        try
        {
            return IVL_TSImpl.valueOf(checkNull(ts), checkNull(bl), checkNull(ts1), checkNull(bl1));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<TS>", throwable);
        }
    }


    public IVL_TS newIVL_TS(TS ts, BL bl, PQ pq, BL bl1) throws Hl7Exception
    {
        if ((ts == null || ts.isNull().isTrue()) && (pq == null || pq.isNull().isTrue()))
            throw newMandatoryException("IVL<TS>", "boundary");
        try
        {
            return IVL_TSImpl.valueOf(checkNull(ts), checkNull(bl), checkNull(pq), checkNull(bl1));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<TS>", throwable);
        }
    }


    public IVL_TS nullIVL_TS(CS cs)
    {
        return IVL_TSImpl.nullIVL_TS(cs);
    }


    public IVL_PQ newIVL_PQ(REAL real, BL bl, REAL real1, BL bl1, CS cs) throws Hl7Exception
    {
        if (cs == null || cs.isNull().isTrue())
            throw newMandatoryException("IVL<PQ>", "unit");
        if ((real == null || real.isNull().isTrue()) && (real1 == null || real1.isNull().isTrue()))
            throw newMandatoryException("IVL<PQ>", "boundary");
        try
        {
            return IVL_PQImpl.valueOf(real, checkNull(bl), real1, checkNull(bl1), cs);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<PQ>", throwable);
        }
    }


    public IVL_PQ newIVL_PQ(BigDecimal bigdecimal, boolean flag, BigDecimal bigdecimal1, boolean flag1, String s) throws Hl7Exception
    {
        REAL real = newREAL(bigdecimal);
        BL bl = newBL(flag);
        REAL real1 = newREAL(bigdecimal1);
        BL bl1 = newBL(flag1);
        CS cs = newCS(s);
        return newIVL_PQ(real, bl, real1, bl1, cs);
    }


    public IVL_PQ newIVL_PQ(PQ pq, boolean flag, PQ pq1, boolean flag1) throws Hl7Exception
    {
        BL bl = newBL(flag);
        BL bl1 = newBL(flag1);
        return newIVL_PQ(pq, bl, pq1, bl1);
    }


    public IVL_PQ newIVL_PQ(PQ pq, BL bl, PQ pq1, BL bl1) throws Hl7Exception
    {
        if ((pq == null || pq.isNull().isTrue()) && (pq1 == null || pq1.isNull().isTrue()))
            throw newMandatoryException("IVL<PQ>", "boundary");
        try
        {
            return IVL_PQImpl.valueOf(checkNull(pq), checkNull(bl), checkNull(pq1), checkNull(bl1));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<PQ>", throwable);
        }
    }


    public IVL_PQ nullIVL_PQ(CS cs)
    {
        return IVL_PQImpl.nullIVL_PQ(cs);
    }


    public IVL_PQ newIVL_PQ(PQ pq) throws Hl7Exception
    {
        if (pq == null || pq.isNull().isTrue())
            return null;
        try
        {
            return IVL_PQImpl.valueOf(pq, BLImpl.TRUE, BLImpl.TRUE);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<PQ>", throwable);
        }
    }


    public TS newTS(Date date, INT int1, PQ pq) throws Hl7Exception
    {
        try
        {
            return TSImpl.valueOf(date, checkNull(int1), checkNull(pq));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("TS", throwable);
        }
    }


    public TS newTS(Date date, INT int1) throws Hl7Exception
    {
        try
        {
            return TSImpl.valueOf(date, checkNull(int1));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("TS", throwable);
        }
    }


    public TS newTS(Date date) throws Hl7Exception
    {
        if (date == null)
            return null;
        try
        {
            return TSImpl.valueOf(date);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("TS", throwable);
        }
    }


    public TS newTS(String s) throws Hl7Exception
    {
        if (s == null || s.trim().equals(""))
            return nullTS(null);
        else
            return TSImpl.getTSByString(s);
    }


    public TS nullTS(CS cs)
    {
        return TSImpl.nullTS(cs);
    }


    public PIVL newPIVL(String s) throws Hl7Exception
    {
        if (s == null)
            return nullPIVL(NullFlavorImpl.NI);
        else
            return PIVL_TSImpl.valueOf(s);
    }


    public PIVL newPIVL(IVL_TS ivl_ts, PQ pq, CS cs, BL bl) throws Hl7Exception
    {
        try
        {
            return PIVL_TSImpl.valueOf(checkNull(ivl_ts), checkNull(pq), checkNull(cs), checkNull(bl));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("PIVL<TS>", throwable);
        }
    }


    public PIVL nullPIVL(CS cs)
    {
        return PIVL_TSImpl.nullPIVL_TS(cs);
    }


    public EIVL newEIVL(String s) throws Hl7Exception
    {
        if (s == null)
            return nullEIVL(NullFlavorImpl.NI);
        else
            return EIVLImpl.valueOf(s);
    }


    public EIVL newEIVL(CS cs, IVL_PQ ivl_pq) throws Hl7Exception
    {
        try
        {
            return EIVLImpl.valueOf(checkNull(cs), checkNull(ivl_pq));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("EIVL", throwable);
        }
    }


    public EIVL newEIVL(String s, IVL_PQ ivl_pq) throws Hl7Exception
    {
        CS cs = newCS(s);
        return newEIVL(cs, ivl_pq);
    }


    public EIVL nullEIVL(CS cs)
    {
        return EIVLImpl.nullEIVL(cs);
    }


    public GTS newGTS(String s) throws Hl7Exception
    {
        if (s == null)
            return nullGTS(NullFlavorImpl.NI);
        else
            return GTSHullImpl.valueOf(s);
    }


    public GTS newGTS(TS ts) throws Hl7Exception
    {
        if (ts == null || ts.isNull().isTrue())
        {
            return nullGTS(NullFlavorImpl.NI);
        }
        else
        {
            IVL_TS ivl_ts = newIVL_TS(ts);
            return newGTS(ivl_ts);
        }
    }


    public GTS newGTS(IVL_TS ivl_ts) throws Hl7Exception
    {
        if (ivl_ts == null || ivl_ts.isNull().isTrue())
            return nullGTS(NullFlavorImpl.NI);
        try
        {
            return GTSHullImpl.valueOf(ivl_ts);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("GTS", throwable);
        }
    }


    public GTS nullGTS(CS cs)
    {
        return GTSNullImpl.nullGTS(cs);
    }


    public OID newOID(String s) throws Hl7Exception
    {
        if (s == null || s.length() == 0)
            return nullOID(NullFlavorImpl.NI);
        try
        {
            return OIDImpl.valueOf(s);
        }
        catch (Exception exception)
        {
            throw ANYImpl.newParseException("OID", s, exception);
        }
        catch (TokenMgrError tokenmgrerror)
        {
            throw ANYImpl.newParseException("OID", s, tokenmgrerror);
        }
    }


    public OID nullOID(CS cs)
    {
        return OIDImpl.nullOID(cs);
    }


    public IVL_MO newIVL_MO(MO mo, BL bl, MO mo1, BL bl1) throws Hl7Exception
    {
        if ((mo == null || mo.isNull().isTrue()) && (mo1 == null || mo1.isNull().isTrue()))
            throw newMandatoryException("IVL<MO>", "boundary");
        try
        {
            return IVL_MOImpl.valueOf(checkNull(mo), checkNull(bl), checkNull(mo1), checkNull(bl1));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<MO>", throwable);
        }
    }


    public IVL_MO newIVL_MO(BigDecimal bigdecimal, boolean flag, BigDecimal bigdecimal1, boolean flag1, String s) throws Hl7Exception
    {
        REAL real = newREAL(bigdecimal);
        BL bl = newBL(flag);
        REAL real1 = newREAL(bigdecimal1);
        BL bl1 = newBL(flag1);
        CS cs = newCS(s);
        return newIVL_MO(real, bl, real1, bl1, cs);
    }


    public IVL_MO newIVL_MO(REAL real, BL bl, REAL real1, BL bl1, CS cs) throws Hl7Exception
    {
        if ((real == null || real.isNull().isTrue()) && (real1 == null || real1.isNull().isTrue()))
            throw newMandatoryException("IVL<MO>", "boundary");
        try
        {
            return IVL_MOImpl.valueOf(checkNull(real), checkNull(bl), checkNull(real1), checkNull(bl1), checkNull(cs));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<MO>", throwable);
        }
    }


    public IVL_MO newIVL_MO(MO mo) throws Hl7Exception
    {
        if (mo == null || mo.isNull().isTrue())
            return nullIVL_MO(NullFlavorImpl.NI);
        try
        {
            return IVL_MOImpl.valueOf(mo, BLImpl.TRUE, mo, BLImpl.TRUE);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<MO>", throwable);
        }
    }


    public IVL_MO nullIVL_MO(CS cs)
    {
        return IVL_MOImpl.nullIVL_MO(cs);
    }


    public IVL_REAL newIVL_REAL(REAL real, BL bl, REAL real1, BL bl1) throws Hl7Exception
    {
        if ((real == null || real.isNull().isTrue()) && (real1 == null || real1.isNull().isTrue()))
            throw newMandatoryException("IVL<REAL>", "boundary");
        try
        {
            return IVL_REALImpl.valueOf(checkNull(real), checkNull(bl), checkNull(real1), checkNull(bl1));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<REAL>", throwable);
        }
    }


    public IVL_REAL newIVL_REAL(BigDecimal bigdecimal, boolean flag, BigDecimal bigdecimal1, boolean flag1) throws Hl7Exception
    {
        REAL real = newREAL(bigdecimal);
        BL bl = newBL(flag);
        REAL real1 = newREAL(bigdecimal1);
        BL bl1 = newBL(flag1);
        return newIVL_REAL(real, bl, real1, bl1);
    }


    public IVL_REAL newIVL_REAL(BigDecimal bigdecimal) throws Hl7Exception
    {
        return newIVL_REAL(newREAL(bigdecimal));
    }


    public IVL_REAL newIVL_REAL(REAL real) throws Hl7Exception
    {
        if (real == null || real.isNull().isTrue())
            return IVL_REALImpl.nullIVL_REAL(NullFlavorImpl.NI);
        try
        {
            return IVL_REALImpl.valueOf(real, BLImpl.TRUE, real, BLImpl.TRUE);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<REAL>", throwable);
        }
    }


    public IVL_REAL nullIVL_REAL(CS cs)
    {
        return IVL_REALImpl.nullIVL_REAL(cs);
    }


    public IVL_RTO_PQ newIVL_RTO_PQ(RTO_PQ rto_pq, BL bl, RTO_PQ rto_pq1, BL bl1) throws Hl7Exception
    {
        if ((rto_pq == null || rto_pq.isNull().isTrue()) && (rto_pq1 == null || rto_pq1.isNull().isTrue()))
            throw newMandatoryException("IVL<RTO<PQ>>", "boundary");
        try
        {
            return IVL_RTO_PQImpl.valueOf(checkNull(rto_pq), checkNull(bl), checkNull(rto_pq1), checkNull(bl1));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<RTO_PQ>", throwable);
        }
    }


    public IVL_RTO_PQ newIVL_RTO_PQ(RTO_PQ rto_pq, boolean flag, RTO_PQ rto_pq1, boolean flag1) throws Hl7Exception
    {
        BL bl = newBL(flag);
        BL bl1 = newBL(flag1);
        return newIVL_RTO_PQ(rto_pq, bl, rto_pq1, bl1);
    }


    public IVL_RTO_PQ newIVL_RTO_PQ(RTO_PQ rto_pq) throws Hl7Exception
    {
        if (rto_pq == null || rto_pq.isNull().isTrue())
            return nullIVL_RTO_PQ(NullFlavorImpl.NI);
        try
        {
            return IVL_RTO_PQImpl.valueOf(rto_pq, BLImpl.TRUE, rto_pq, BLImpl.TRUE);
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("IVL<RTO<PQ>>", throwable);
        }
    }


    public IVL_RTO_PQ nullIVL_RTO_PQ(CS cs)
    {
        return IVL_RTO_PQImpl.nullIVL_RTO_PQ(cs);
    }


    public RTO_MO_PQ newRTO_MO_PQ(MO mo, PQ pq) throws Hl7Exception
    {
        try
        {
            return RTO_MO_PQImpl.valueOf(checkNull(mo), checkNull(pq));
        }
        catch (Throwable throwable)
        {
            throw newFactoryException("RTO<MO_PQ>", throwable);
        }
    }


    public RTO_MO_PQ nullRTO_MO_PQ(CS cs)
    {
        return RTO_MO_PQImpl.nullRTO_MO_PQ(cs);
    }


    private static Hl7Exception newMandatoryException(String s, String s1)
    {
        String as[] = { "PARAM", "CLASS" };
        String as1[] = { s1, s };
        String s2 = MessageUtils.getMessage("必须的参数提供给 factory 方法", as, as1);
        return new RimDataTypeException("CORE_MANDATORY_ATTRIBUTE", s2);
    }


    private static Hl7Exception newFactoryException(String s, Throwable throwable)
    {
        String as[] = { "CLASS", "CAUSE" };
        String as1[] = { s, throwable.getMessage() };
        String s1 = MessageUtils.getMessage("An error occurred while constructing a new instance of &CLASS: &CAUSE", as, as1);
        return new RimDataTypeException("CORE_DATATYPE_FACTORY", s1, throwable);
    }


    private static ED checkNull(ED ed)
    {
        if (ed == null)
            return EDImpl.nullED(NullFlavorImpl.NI);
        else
            return ed;
    }


    private static TEL checkNull(TEL tel)
    {
        if (tel == null)
            return TELImpl.nullTEL(NullFlavorImpl.NI);
        else
            return tel;
    }


    private static BIN checkNull(BIN bin)
    {
        if (bin == null)
            return STImpl.nullST(NullFlavorImpl.NI);
        else
            return bin;
    }


    private static CS checkNull(CS cs)
    {
        if (cs == null)
            return CSImpl.nullCS(NullFlavorImpl.NI);
        else
            return cs;
    }


    private static CE checkNull(CE ce)
    {
        if (ce == null)
            return CEImpl.nullCE(NullFlavorImpl.NI);
        else
            return ce;
    }


    @SuppressWarnings("unused")
    private static UID checkNull(UID uid)
    {
        if (uid == null)
            return UIDImpl.nullUID(NullFlavorImpl.NI);
        else
            return uid;
    }


    private static ST checkNull(ST st)
    {
        if (st == null)
            return STImpl.nullST(NullFlavorImpl.NI);
        else
            return st;
    }


    private static BL checkNull(BL bl)
    {
        if (bl == null)
            return BLImpl.nullBL(NullFlavorImpl.NI);
        else
            return bl;
    }


    private static GTS checkNull(GTS gts)
    {
        if (gts == null)
            return GTSNullImpl.nullGTS(NullFlavorImpl.NI);
        else
            return gts;
    }


    private static SET_CS checkNull(SET_CS set_cs)
    {
        if (set_cs == null)
            return SET_CSImpl.nullSET_CS(NullFlavorImpl.NI);
        else
            return set_cs;
    }


    @SuppressWarnings("unused")
    private static ADXP checkNull(ADXP adxp)
    {
        if (adxp == null)
            return ADXPImpl.nullADXP(NullFlavorImpl.NI);
        else
            return adxp;
    }


    @SuppressWarnings("unused")
    private static ENXP checkNull(ENXP enxp)
    {
        if (enxp == null)
            return ENXPImpl.nullENXP(NullFlavorImpl.NI);
        else
            return enxp;
    }


    private static IVL_TS checkNull(IVL_TS ivl_ts)
    {
        if (ivl_ts == null)
            return IVL_TSImpl.nullIVL_TS(NullFlavorImpl.NI);
        else
            return ivl_ts;
    }


    private static PQ checkNull(PQ pq)
    {
        if (pq == null)
            return PQImpl.nullPQ(NullFlavorImpl.NI);
        else
            return pq;
    }


    private static INT checkNull(INT int1)
    {
        if (int1 == null)
            return INTImpl.nullINT(NullFlavorImpl.NI);
        else
            return int1;
    }


    private static TS checkNull(TS ts)
    {
        if (ts == null)
            return TSImpl.nullTS(NullFlavorImpl.NI);
        else
            return ts;
    }


    private static REAL checkNull(REAL real)
    {
        if (real == null)
            return REALImpl.nullREAL(NullFlavorImpl.NI);
        else
            return real;
    }


    private static IVL_PQ checkNull(IVL_PQ ivl_pq)
    {
        if (ivl_pq == null)
            return IVL_PQImpl.nullIVL_PQ(NullFlavorImpl.NI);
        else
            return ivl_pq;
    }


    private static MO checkNull(MO mo)
    {
        if (mo == null)
            return MOImpl.nullMO(NullFlavorImpl.NI);
        else
            return mo;
    }


    private static RTO_PQ checkNull(RTO_PQ rto_pq)
    {
        if (rto_pq == null)
            return RTO_PQImpl.nullRTO_PQ(NullFlavorImpl.NI);
        else
            return rto_pq;
    }


    protected static String getRcsId()
    {
        return RCS_ID;
    }


    protected static boolean isRcsIdRecorded()
    {
        return RCS_ID_RECORDED;
    }


    protected static String getClassKey()
    {
        return CLASS_KEY;
    }


    protected static String getMethodKey()
    {
        return METHOD_KEY;
    }


    protected static String getParamKey()
    {
        return PARAM_KEY;
    }


    protected static String getCauseKey()
    {
        return CAUSE_KEY;
    }


    protected static String getMandatoryCode()
    {
        return MANDATORY_CODE;
    }


    protected static String getFactoryCode()
    {
        return FACTORY_CODE;
    }


    protected static String getMandatoryMessage()
    {
        return MANDATORY_MESSAGE;
    }


    protected static String getFactoryMessage()
    {
        return FACTORY_MESSAGE;
    }

}
